package com.design01_builder.pattern02_factory.factory_method.controller;

import com.design01_builder.pattern02_factory.factory_method.factory.DiscountFreeGoodsFactory;
import com.design01_builder.pattern02_factory.factory_method.factory.FreeGoodsFactory;
import com.design01_builder.pattern02_factory.factory_method.factory.SmallGiftFreeGoodsFactory;
import com.design01_builder.pattern02_factory.simple_factory.entry.AwardInfo;
import com.design01_builder.pattern02_factory.simple_factory.entry.ResponseResult;
import com.design01_builder.pattern02_factory.simple_factory.service.IFreeGoods;

/**
 * @ClassName DeliverController
 * @Description TODO
 * @Author zhangjunhao
 * @DATE 2023/9/2 1:56
 */
public class DeliverController {

    /**
     * 按照类型的不同发放商品
     */
    public ResponseResult awardToUser(AwardInfo awardInfo){
        FreeGoodsFactory freeGoodsFactory = null;
        if(awardInfo.getAwardTypes() == 1){
            freeGoodsFactory = new DiscountFreeGoodsFactory();
        }else if(awardInfo.getAwardTypes() == 2){
            freeGoodsFactory = new SmallGiftFreeGoodsFactory();
        }
        IFreeGoods freeGoods = freeGoodsFactory.getInstance();
        System.out.println("=====工厂方法模式========");
        ResponseResult result = freeGoods.sendFreeGoods(awardInfo);
        return result;
    }
}
